// subcontract/home/pages/openSearch/index.js
const $api = require('../../../../request/api').API;
const app = getApp();
import Toast from '../../../../miniprogram_npm/@vant/weapp/toast/toast';
const {
	menuBtnTop,
	menuBtnHeight,
	menuBtnWidth,
	menuBtnLeft
} = app.globalData;

Page({
	/**
	 * 页面的初始数据
	 */
	data: {
		menuBtnTop,
		menuBtnHeight,
		menuBtnWidth,
		menuBtnLeft: menuBtnLeft - 5,
		name: '',
		pageNo: 1,
		list: []
	},

	getData() {
		Toast.loading({message:'加载中',duration:0})
		let {
			name,
			pageNo,
			list
		} = this.data
		$api.openSearch({
			name,
			pageNo,
			pageSize: 10
		}).then(res=>{
			Toast.clear()
			if(res.data.status==0){
				pageNo==1?list = res.data.data.list:list.concat(res.data.data.list)
				this.setData({
					list
				})
			}
		})
	},

	// 搜索
	handleSearchGoods() {
		this.setData({
			pageNo:1,
			list:[]
		})
		this.getData()
	},

	// 输入
	handleInput(e) {
		this.setData({
			name: e.detail
		});
	},

	//绑定呼叫器
	bindBeeper(e){
		const id = e.currentTarget.dataset.id
		 // 绑定呼叫器页
		 wx.navigateTo({
			 url:'../../../../pages/index/bindingBeeper/index?hc='+id
		 })
	},

	back(){
		wx.navigateBack(-1)
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.setData({
			name:options.name
		})
		this.getData()
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {
		this.setData({
			pageNo:1
		})
		this.getData()
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {
		let pageNo = this.data.pageNo
		pageNo+=1
		this.setData({
			pageNo:pageNo
		})
		this.getData()
	},
})